package com.mytest.offer;

import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;

@Slf4j
public class SolutionJZ23 {

    public static void main(String[] args) {
        SolutionJZ23 solutionJZ6 = new SolutionJZ23();
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);

        listNode.next = listNode1;
        listNode1.next = listNode2;

        solutionJZ6.entryNodeOfLoop(listNode);
    }

    public ListNode entryNodeOfLoop(ListNode pHead) {
        HashSet<ListNode> hset = new HashSet<>();
        while(pHead != null){
            if(hset.contains(pHead)){
                return pHead;
            }
            hset.add(pHead);
            pHead = pHead.next;
        }
        return null;
    }
}
